<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>


    <footer th:fragment="table">
        <div class="tpl-content-wrapper">
            <div class="row-content am-cf">
                <div class="row">
                    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                        <div class="widget am-cf">
                            <div class="widget-head am-cf">
                                <div class="widget-title  am-cf">项目简介</div>
                            </div>
                            <div class="widget-body  am-fr">
                                <div class="am-u-sm-12 am-u-md-6 am-u-lg-4">
                                    <div class="am-form-group">
                                        <div class="am-btn-toolbar">
                                            <div class="am-btn-group am-btn-group-xs">
                                                <button type="button" class="am-btn am-btn-default am-btn-danger" onclick="del()"><span class="am-icon-trash-o"></span> 删除</button>
                                                <button type="button" class="am-btn am-btn-default am-btn-warning" data-toggle="modal" data-target="#myimportModal"><span class="am-icon-plus"></span> 导入</button>
                                                <button type="button" class="am-btn am-btn-default am-btn-secondary" onclick="derive()"><span class="am-icon-trash-o"></span> 导出</button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="am-u-sm-12 am-u-md-6 am-u-lg-2">
                                    <div class="am-form-group tpl-table-list-select">
                                        <select data-am-selected="{btnSize: 'sm'}" id="borrowstatus"  class="selectOption">
                                            <option value="">请选择</option>
                                            <option value="房产抵押" th:selected="${borrowstatus=='房产抵押'}" >房产抵押</option>
                                            <option value="车辆抵押" th:selected="${borrowstatus=='车辆抵押'}">车辆抵押</option>
                                            <option value="信用贷款" th:selected="${borrowstatus=='信用贷款'}">信用贷款</option>
                                            <option value="零首付车贷" th:selected="${borrowstatus=='零首付车贷'}">零首付车贷</option>
                                        </select>
                                        <select data-am-selected="{btnSize: 'sm'}" id="pagesize"  class="selectOption">
                                            <option value="">请选择</option>
                                            <option value="5" th:selected="${pagesize==5}">5</option>
                                            <option value="10" th:selected="${pagesize==10}">10</option>
                                            <option value="10" th:selected="${pagesize==15}">15</option>
                                            <option value="10" th:selected="${pagesize==20}">20</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="am-u-sm-12 am-u-md-6 am-u-lg-2">
                                    <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                                        <input type="date" class="am-form-field" th:value="${#dates.format(predate,'yyyy-MM-dd')}" id="predate">
                                    </div>
                                </div>
                                <div class="am-u-sm-12 am-u-md-6 am-u-lg-2">
                                    <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                                        <input type="date" class="am-form-field " th:value="${#dates.format(nextdate,'yyyy-MM-dd')}" id="nextdate">
                                    </div>
                                </div>
                                <div class="am-u-sm-12 am-u-md-6 am-u-lg-2">
                                    <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                                        <input type="text" class="am-form-field " id="borrowkeyword" th:value="${borrowkeyword}">
                                        <span class="am-input-group-btn">
                                         <button class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search"
                                                 type="button" th:onclick="|page('${userBorrow.pageNum}')|"></button>
                                    </span>
                                    </div>
                                </div>

                                <div class="am-u-sm-12">
                                     <div style="overflow-x:scroll"><table class="am-table am-table-compact am-table-striped tpl-table-black " id="example-r" style="width: 2000px">
                                         <thead>
                                         <tr>
                                             <th><button onclick="reSelect()" class="am-btn  am-btn-default am-btn-success tpl-table-list-field" type="button">反选</button></th>
                                             <th>编号</th>
                                             <th>用户名称</th>
                                             <th>贷款名称</th>
                                             <th>贷款金额</th>
                                             <th>贷款余额</th>
                                             <th>起初贷款时间</th>
                                             <th>最后还款时间</th>
                                             <th>贷款期限</th>
                                             <th>贷款描述</th>
                                             <th>借款情况</th>
                                             <th>贷款手机号</th>
                                             <th>借款用途</th>
                                             <th>担保方式</th>
                                             <th>担保物数量</th>
                                             <th>担保物总价格</th>
                                             <th>还款方式</th>
                                             <th>操作</th>
                                         </tr>
                                         </thead>
                                         <tbody>
                                         <tr class="gradeX" th:each="borrow,s : ${userBorrow.list}">
                                             <td><input type="checkbox" name="persons" th:value="${borrow.loansId}" class="choice"></td>
                                             <th th:text="${s.index}">编号</th>
                                             <th th:text="${borrow.realName}">用户名称</th>
                                             <th th:text="${borrow.loansName}">贷款名称</th>
                                             <th th:text="${borrow.loansMoney}">贷款金额</th>
                                             <th th:text="${borrow.userBalance}">贷款余额</th>
                                             <th th:text="${#dates.format(borrow.loansTime,'yyyy-MM-dd')}">起初贷款时间</th>
                                             <th th:text="${#dates.format(borrow.dealTime,'yyyy-MM-dd')}">最后还款时间</th>
                                             <th th:text="${borrow.Time}">贷款期限</th>
                                             <th th:text="${borrow.loansDescribe}">贷款描述</th>
                                             <th th:text="${borrow.loansState}">借款情况</th>
                                             <th th:text="${borrow.loansPhone}">贷款手机号</th>
                                             <th th:text="${borrow.usemethodName}">借款用途</th>
                                             <th th:text="${borrow.ltypeName}">担保方式</th>
                                             <th th:text="${borrow.loansStatus}">还款状态</th>
                                             <th th:text="${borrow.loansTotalvalue}">担保物总价格</th>
                                             <th th:text="${borrow.repayName}">还款方式</th>
                                             <td>
                                                 <div class="tpl-table-black-operation">
                                                     <a href="javascript:;" th:onclick="|addMonthLoans('${borrow.loansId}')|">
                                                         <i class="am-icon-lock" th:text="${borrow.loansStatus=='已还款'?'已审核':'审核'}"></i>
                                                         </a>

                                                     <a href="javascript:;" data-toggle="modal" data-target="#myModal" th:onclick="|findmost('${borrow.loansId}')|">更多信息</a>
                                                     <a href="javascript:;" class="tpl-table-black-operation-del">
                                                         <i class="am-icon-trash" th:onclick="|delone('${borrow.loansId}')|"></i> 删除
                                                     </a>
                                                 </div>
                                             </td>
                                         </tr>
                                         </tbody>
                                     </table></div>

                                    <div class="am-u-lg-12 am-cf">
                                        <div class="am-u-lg-3">
                                            跳转至:<input type="number" id="num"  class="selectOption">/ 页
                                            <span>
                                            <button class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search" type="button" th:onclick="findpage()"></button>
                                        </span>
                                        </div>

                                        <div class="am-fr">
                                            <ul class="am-pagination tpl-pagination">
                                                <li ><a href="javascript:" th:onclick="|page('${userBorrow.navigateFirstPage}')|">首页</a></li>
                                                <li  th:if="userBorrow.hasPreviousPage"><a href="javascript:" th:onclick="|page('${userBorrow.prePage}')|">«</a></li>


                                                <li th:each="pageNum:${#numbers.sequence(1,userBorrow.pages)}">
                                                    <a th:text="${pageNum}" th:onclick="|page('${pageNum}')|"></a>
                                                </li>


                                                <li th:if="userBorrow.hasNextPage"><a href="javascript:" th:onclick="|page('${userBorrow.nextPage}')|">»</a></li>
                                                <li><a href="javascript:" th:onclick="|page('${userBorrow.navigateLastPage}')|">尾页</a></li>
                                            </ul>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>


            <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="margin-top: 300px">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title" id="myModalLabel">查看充值更多信息</h4>
                        </div>

                        <div id="model">

                        </div>

                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        </div>
                    </div><!-- /.modal-content -->
                </div><!-- /.modal -->
            </div>


            <!--导入模态框-->
            <div class="modal fade" id="myimportModal" tabindex="-1" role="dialog" aria-labelledby="myimportModalLabel" aria-hidden="true" style="margin-top: 300px">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title" id="myimportModalLabel">查看充值更多信息</h4>
                        </div>
                        请选择需要上传的文件：<input type="file" name="file" id="importfile">
                        <div class="modal-footer">
                            <button type="button" class="btn btn-primary" data-dismiss="modal" onclick="importscore2()">提交</button>
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        </div>
                    </div><!-- /.modal-content -->
                </div><!-- /.modal -->
            </div>

        </div>
    </footer>
    <script>

        function page(i) {
            $.ajax({
                url:"/p2p/myborrow/getUserBorrow",
                data:{
                    "borrowstatus":$("#borrowstatus").val(),
                    "predate":$("#predate").val(),
                    "nextdate":$("#nextdate").val(),
                    "borrowkeyword":$("#borrowkeyword").val(),
                    "pagenum":i,
                    "pagesize":$("#pagesize").val(),
                },
                type:"get",
                dataType:"html",
                success:function (data) {
                    $("#content").html(data)
                }
            })
        }

        function findpage() {
            var pagesnum=$('#num').val();
            page(pagesnum);
        }


        function findmost(i) {
            $.ajax({
                url: "/p2p/myborrow/getborrowdetail",
                data:{"id":i},
                type: "get",
                dataType:"json",
                success:function (data) {
                    console.log(data)
                    var s="";
                    s+="<div class=\"modal-body\">\n" +
                        "贷款人的真实姓名:<div>"+data.userRealname+"</div>\n" +
                        "用户账户余额:<div>"+data.userBalance+"</div>\n" +
                        "贷款金额:<div>"+data.loansAmount+"</div>\n" +
                        "贷款时间:<div>"+data.loansDealtime+"</div>\n" +
                        "还款时间:<div>"+data.loansPaytime+"</div>\n" +
                        "贷款期限:<div>"+data.loansTime+"</div>\n" +
                        "还款状态:<div>"+data.loansStatus+"</div>\n" +
                        "\n" +
                        "</div>"
                    $('#model').html(s)
                },
            })
        }

        function addMonthLoans(i) {
            $.ajax({
                url: "/p2p/myborrow/addMonthLoans",
                data:{"id":i},
                type: "get",
                dataType:"json",
                success:function (data) {
                       if(data==0){
                           alert("审核通过")
                       }
                },
            })
        }

        $(".choice").click(function () {
            if($(this).prop("checked")){
                if(!($(this).val() in bors)){
                    bors.push($(this).val())
                }
            }else if(!$(this).prop("checked")){
                for (var i=0;i<bors.length;i++){
                    if(bors[i]===$(this).val()){
                        bors.splice(i,1);
                    }
                }
            }
        })

        //删除单个
        function delone(i) {
            $.ajax({
                url:"/p2p/myborrow/deloneborrow",
                data:{
                    "id":i,
                },
                type:"get",
                dataType:"text",
                success:function (data) {
                    if(data==1){
                        alert("恭喜删除成功")
                        page(1);
                    }else{
                        alert("清先删除项目,再进行删除,删除失败!")
                    }
                }
            })
        }

        //批量删除
        function del() {
            var ides=bors;
            $.ajax({
                url:"/p2p/myborrow/delallborrow",
                data:{
                    "id":ides,
                },
                type:"get",
                dataType:"text",
                success:function (data) {
                    if(data==1){
                        alert("恭喜删除成功");
                        page(1);
                        bors=[];
                    }else {
                        alert("清先删除项目,再删除项目公司还款信息,谢谢!");
                    }
                }
            })
        }


        /*导出*/
        function derive() {
            if(bors.length>0){
                location.href="/p2p/myborrow/outputborrow?ids="+bors
                bors=[];
            }else{
                alert("请先选择")
            }
        }

        //导入
        function importscore2() {
            var form = new FormData();
            form.append("file", document.getElementById("importfile").files[0]);
            $.ajax({
                url:"/p2p/myborrow/inborrow",
                data:form,
                type:"post",
                dataType:"text",
                processData: false,
                contentType: false,
                success:function (data) {
                    if(data==1){
                        page(1);
                        alert("导入成功")
                    }else{
                        alert("导入失败")
                    }
                },
            })
        }




    </script>
</head>
</html>
